%% This m-file is to display the 2D raw data and save to  *.mat 
% The 1st step to analyze florescence data
% The next step is Flores_2D_display4pub.m for publication


close all
clear all
clc

DataFile={ % *.dat
    % 'sphingo3.dat'; % NaCl
    % 'sphingo4.dat'; % KI
    % 'sphingo3.dat'; % CaCl2
    % 'sphingo3.dat'; % LaCl3 + KCl
    'water1.dat'; % Water
    
}

MCAfile={ 
    % 2D data (energy,qz, intensity) *.mca
    % 'sphingo3.dat.scan255.mca'; % NaCl + FeCl3
    % 'sphingo4.dat.scan72.mca';  % KI + FeCl3
    % 'sphingo3.dat.scan317.mca'; % CaCl2 + FeCl3
    % 'sphingo3.dat.scan90.mca';  % LaCl3 +KCl
    'water1.dat.scan36.mca'; %Water
    }

MONScanNum={% integer scan number
    % 255; % NaCl + FeCl3
    % 25;  % KI + FeCl3
    % 317; % CaCl2 + FeCl3
    % 90;  % LaCl3 +KCl
    36; % Water
    }

MATfile={ % output _raw.mat
    % 'sphingo3_scan255_raw.mat'; % NaCl + FeCl3
    % 'sphingo4_scan72_raw.mat'; % KI + FeCl3
    % 'sphingo3_scan317_raw.mat';% CaCl2 + FeCl3
    % 'sphingo3_scan90_raw.mat';% LaCl3 +KCl
    'water1_scan36_raw.mat'; %Water
    }

%%  To save the 2D data in a matrix in a MAT file and later to be reloaded
% use mcaread.m script version 1.0
% The 2D data 

close all
clc
CalibCoef=[0.0113,-0.1272];  % Channel->Energy calibration coefficients AMES 2015 detector
for k=1:length(MCAfile)
    [mca,energy,qz,ct]=mcaread(MCAfile{k},CalibCoef);
    Mon_data=plcol(DataFile{k},MONScanNum{k},'MonitorA');
    mon=Mon_data'; % Row vector (each row element corresponds to a Qz);
    imagesc(qz,energy(100:1000),mca(100:1000,:));
    set(gca,'ydir','norm');
    pause(5)
    save(MATfile{k},'mca','energy','qz','ct','mon');
end









